package com.yc.chaoshi.cs_manage.controller;


import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yc.chaoshi.cs_manage.mapper.PmsFenlei3Mapper;
import com.yc.chaoshi.entity.PmsFenlei2;
import com.yc.chaoshi.entity.PmsFenlei3;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xz
 * @since 2022-08-04
 */
@RestController
@RequestMapping("/chaoshi/pmsFenlei3")
public class PmsFenlei3Controller {

    @Resource
    private PmsFenlei3Mapper fenlei3Mapper;

    @GetMapping("queryFenlei3")
    List<PmsFenlei3> queryFenlei3(){
        return fenlei3Mapper.selectList(null);
    }
    @RequestMapping("selectFenlei3")
    public Page selectFenlei3(@RequestParam(defaultValue = "") String cname,
                              @RequestParam(defaultValue = "1") int page){
        Page<PmsFenlei3> ipage = new Page<>(page,10);
        ipage.orders().add(OrderItem.asc("cid"));
        System.out.println(fenlei3Mapper.selectfenlei3(cname, (page - 1) * 10,10));
        ipage.setRecords(fenlei3Mapper.selectfenlei3(cname, (page - 1) * 10,10));
        System.out.println(fenlei3Mapper.selectfenlei3(cname,0,1000).size());
        long total = fenlei3Mapper.selectfenlei3(cname,0,1000).size();
        ipage.setTotal(total);
        return ipage;
    }
    @RequestMapping("selectFlname")
    public Page selectFlname(){
        Page<PmsFenlei3> ipage = new Page<>(0,1000);
        ipage.orders().add(OrderItem.asc("cid"));
        ipage.setRecords(fenlei3Mapper.selectfenlei3("",0,1000));
        return ipage;
    }

    @RequestMapping("deleteFenlei3")
    public int deleteFenlei3(@RequestParam int cid){
        fenlei3Mapper.deletefenlei3(cid);
        return 0;
    }

    @RequestMapping("insertFenlei3")
    public int insertFenlei3(@RequestParam String cname,
                             @RequestParam int bid,
                             @RequestParam int display,
                             @RequestParam String des){
        fenlei3Mapper.insertfenlei3(cname, bid, display, des);
        return 0;
    }

    @RequestMapping("updateFenlei3")
    public int updateFenlei3(@RequestParam String cname,
                             @RequestParam int bid,
                             @RequestParam int display,
                             @RequestParam String des,
                             @RequestParam int cid) {
        fenlei3Mapper.updatefenlei3(cname, bid, display, des, cid);
        return 0;
    }

}

